import { BaseEntityService } from "./base-entity.service";
import httpClient from "./http-client";

export class PortalUserService extends BaseEntityService {
    baseUrl = "/api/v1.0/admin/portal/user";

    async page(no, size, searchObj) {
        no = no != null ? no : 1;
        size = size != null ? size : 10;
        // 前端从1开始计数，后端从0开始计数
        no = no - 1;
        return httpClient.post(`${this.baseUrl}/page?no=${no}&size=${size}`, {
            ...searchObj,
        }).then((res) => {
            if (res.data.data) {
                const page = res.data.data;
                // 前端从1开始计数，后端从0开始计数
                page.number = page.number + 1;
                return Promise.resolve(page);
            } else {
                throw "no data";
            }
        });
    }

    async retrieve(id) {
        return httpClient.get(`${this.baseUrl}/retrieve/${id}`).then((res) => {
            return Promise.resolve(res.data.data);
        });
    }
}

const portalUserService = new PortalUserService();

export default portalUserService;